home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / C++ A'Link Files / 1989 / 0030-Re ?Overloading the -Dec89 < prev    next >
Encoding:
Text File  |  1991-03-06  |  1.5 KB  |  43 lines  |  [TEXT/GEOL]

  1. Item forwarded  by  ALCABES      to CPLUS.APPLE$
  2.  
  3. Item    8289649                         24-Dec-89        08:06
  4.  
  5. From:   MIKE.VILOT                      ObjectWare, Michael Vilot,PRT
  6.  
  7. To:     MADA.EUROPE                     MacApp Dev Assoc Europe, E Carrasco
  8.  
  9. cc:     CPLUS.DEV$                      C++ Interest List--Developers
  10.  
  11. Sub:    Re: ?Overloading the new…
  12.  
  13. Try this:
  14.   Class TGraphicSegment {       // a PointerObject
  15.       private:
  16.          long   fSize
  17.          long   fAddress
  18.          /* ... */
  19.       public:
  20.          void* operator new(size_t);        // class-specific allocation
  21.          void* operator new(size_t, void*); // at a specfic placement
  22.          void  operator delete(void*);      // class-specific deallocation
  23.          void  operator delete(void*, size_t);  // of an array of objects
  24.          /* ... */
  25.       };
  26. ... if you really have to overload the operators.
  27. >Objects and their fields have to be
  28. >places in a specific location in our heap (a big block allocated at the
  29. >beginning of the application). Each object knows its size, location, and other
  30. >properties.
  31.     Note that you can use the placement syntax with the existing, global
  32. operators new & delete to achieve the effect of allocating at a specific
  33. location:
  34.     // see p. 79 of the C++ Reference Manual
  35.     static char buf[sizeof(X)];
  36.     X* p = new(&buf) X(args);
  37. Also, note that the compiler knows the size of objects, and passes this size
  38. as the first parameter to operator new.
  39.  
  40. Hope this helps,
  41.     Mike
  42.  
  43.